package com.badminton.HubSys.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.badminton.HubSys.mapper.EquipmentHubMapper;
import com.badminton.HubSys.domain.EquipmentHub;
import com.badminton.HubSys.service.IEquipmentHubService;

@Service
public class EquipmentHubServiceImpl implements IEquipmentHubService {
    @Autowired
    private EquipmentHubMapper equipmentHubMapper;

    @Override
    public EquipmentHub selectEquipmentHubByEquipmentid(Long equipmentid) {
        return equipmentHubMapper.selectEquipmentHubByEquipmentid(equipmentid);
    }

    @Override
    public List<EquipmentHub> selectEquipmentHubList(EquipmentHub equipmentHub) {
        return equipmentHubMapper.selectEquipmentHubList(equipmentHub);
    }

    @Override
    public int insertEquipmentHub(EquipmentHub equipmentHub) {
        return equipmentHubMapper.insertEquipmentHub(equipmentHub);
    }

    @Override
    public int updateEquipmentHub(EquipmentHub equipmentHub) {
        return equipmentHubMapper.updateEquipmentHub(equipmentHub);
    }

    @Override
    @Transactional
    public int deleteEquipmentRecommendationByEquipmentID(Long equipmentid) {
        return equipmentHubMapper.deleteEquipmentRecommendationByEquipmentID(equipmentid);
    }

    @Override
    @Transactional
    public int deleteEquipmentReviewByEquipmentID(Long equipmentid) {
        return equipmentHubMapper.deleteEquipmentReviewByEquipmentID(equipmentid);
    }

    @Override
    @Transactional
    public int deleteUserFavoritesByEquipmentID(Long equipmentid) {
        return equipmentHubMapper.deleteUserFavoritesByEquipmentID(equipmentid);
    }

    @Override
    @Transactional
    public int deleteEquipmentHubByEquipmentids(Long[] equipmentids) {
        for (Long equipmentid : equipmentids) {
            deleteEquipmentHubByEquipmentid(equipmentid);
        }
        return equipmentids.length;
    }

    @Override
    @Transactional
    public int deleteEquipmentHubByEquipmentid(Long equipmentid) {
        deleteEquipmentRecommendationByEquipmentID(equipmentid);
        deleteEquipmentReviewByEquipmentID(equipmentid);
        deleteUserFavoritesByEquipmentID(equipmentid);
        return equipmentHubMapper.deleteEquipmentHubByEquipmentid(equipmentid);
    }
}
